package com.qingke.xml.exerice;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class Dom4jTest {

	public static void main(String[] args) {
		
		try {
			long start = System.currentTimeMillis();
			SAXReader reader = new SAXReader();
			Document document = reader.read("sample.xml");
			
			Element root = document.getRootElement();
			for (Object obj: root.elements()) {
				Element child = (Element)obj;
				if (!"student".equals(child.getName())) {
					continue;
				}
				
				System.out.println("------ Student ------");
				System.out.println("id:" + child.attributeValue("id"));
				System.out.println("name:" + child.elementText("name"));
				System.out.println("gender:" + child.elementText("gender"));
				System.out.println("age:" + child.elementText("age"));
			}
			System.out.println("dom4j:" + (System.currentTimeMillis() - start));
		} catch (DocumentException e) {
			e.printStackTrace();
		}
	}

}
